package com.tbit.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 应用上下文
 *
 * @author <a href="mailto:zhang.zhiliang@tbit.com.cn">Zhang ZhiLiang</a>
 * @version 1.0
 * @see <a href="http://adsl1.tbit.com.cn:21490/pages/viewpage.action?pageId=82182491">订单号规范</a>
 * @since 2024/7/4
 */
public class ThreadContextUtil {

    private static final ThreadLocal<Map<String, Object>> threadLocalContext = ThreadLocal.withInitial(HashMap::new);

    public static Object get(String key) {
        return threadLocalContext.get().get(key);
    }

    public static void set(String key, Object value) {
        threadLocalContext.get().put(key, value);
    }

    public static void remove(String key) {
        threadLocalContext.get().remove(key);
    }

    public static void clear() {
        threadLocalContext.get().clear();
    }

    public static Map<String, Object> getContext() {
        return threadLocalContext.get();
    }

    public static void setContext(Map<String, Object> context) {
        threadLocalContext.set(context);
    }

    public static void removeContext() {
        threadLocalContext.remove();
    }



}
